package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.rest.entity.RestDict;
import cn.stylefeng.guns.sys.modular.system.entity.AttendAuditBtyArea;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPerformanceMonthCheck;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPerformanceMonthConfig;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyPerformanceMonthConfigMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPerformanceMonthConfigParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyPerformanceMonthCheckResult;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyPerformanceMonthConfigResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyPerformanceMonthConfigService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wjk
 * @since 2022-02-10
 */
@Service
public class BtyPerformanceMonthConfigServiceImpl extends ServiceImpl<BtyPerformanceMonthConfigMapper, BtyPerformanceMonthConfig> implements BtyPerformanceMonthConfigService {

    @Override
    public void add(BtyPerformanceMonthConfigParam param){
        BtyPerformanceMonthConfig entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyPerformanceMonthConfigParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyPerformanceMonthConfigParam param){
        BtyPerformanceMonthConfig oldEntity = getOldEntity(param);
        BtyPerformanceMonthConfig newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyPerformanceMonthConfigResult findBySpec(BtyPerformanceMonthConfigParam param){
        return null;
    }

    @Override
    public List<BtyPerformanceMonthConfigResult> findListBySpec(BtyPerformanceMonthConfigParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyPerformanceMonthConfigParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }


    /**
     *
     * 查询可以操作绩效的职位
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @Override
    public List<BtyPerformanceMonthConfig> getOperation() {
        LambdaQueryWrapper<BtyPerformanceMonthConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BtyPerformanceMonthConfig::getType,"operation");
        queryWrapper.eq(BtyPerformanceMonthConfig::getCode,"0");
        return this.list(queryWrapper);
    }

    /**
     *
     * 查询可以被做绩效的职位
     *
     * @author wjk
     * @Date 2022-02-10
     */
    @Override
    public List<BtyPerformanceMonthConfig> getPerformance() {
        LambdaQueryWrapper<BtyPerformanceMonthConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BtyPerformanceMonthConfig::getType,"performance");
        queryWrapper.eq(BtyPerformanceMonthConfig::getCode,"0");
        return this.list(queryWrapper);
    }

    /**
     * 获取允许做绩效的天数列表
     *
     * @Date 2022-02-11
     */
    @Override
    public List<RestDict> getPerformanceDay(){
        return this.baseMapper.getPerformanceDay();
    }
        
    private Serializable getKey(BtyPerformanceMonthConfigParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyPerformanceMonthConfig getOldEntity(BtyPerformanceMonthConfigParam param) {
        return this.getById(getKey(param));
    }

    private BtyPerformanceMonthConfig getEntity(BtyPerformanceMonthConfigParam param) {
        BtyPerformanceMonthConfig entity = new BtyPerformanceMonthConfig();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
